<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\LinkPager;
use yii\helpers\Url;
$this->params['breadcrumbs'][] = $this->title;

?>
<style type="text/css">.topFixed{line-height: 24px;}</style>
  <div class=" index fenlei goodsList" id="ininint">

    <div class="weui_navbar topFixed fenleiTop">
      <a href="<?php if(Yii::$app->request->get('lv2')){echo '/category';}else{echo '/';}?>" style="color:black;"><i class="iconfont icon-return"></i></a>
      <div class="weui_cell_bd weui_cell_primary">
        <div class="weui_search_bar" id="search_bar">
          <form class="weui_search_outer" action="/product" method="get" onsubmit="return checkform();">
            <div class="weui_search_inner">
              <i class="weui_icon_search"></i>
              <input type="search" name="name" class="weui_search_input" id="search_input" placeholder="搜索">
              <a href="javascript:" class="weui_icon_clear" id="search_clear"></a>
            </div>
            <label for="search_input" class="weui_search_text" id="search_text">
              <i class="weui_icon_search"></i>
              <span>搜索</span>
            </label>
          </form>
          <div class="searchBtn"><i class="weui_icon_search"></i></div>
        </div>
      </div>
      <a href="/" style="color:black;"><i class="iconfont icon-home"></i></a>
    </div>

    <?php if (Yii::$app->request->get()): ?>
      <div class="weui_cells weui_cells_form" >
        <div class="weui_cell" style="text-align:center">
          <p>“
            <?php if (Yii::$app->request->get('name')): ?>
              <span style="color:#FFAE00"><?=Html::encode(Yii::$app->request->get('name'))?></span>
            <?php else: ?>
                <span style="color:#FFAE00"><?=Html::encode($seach_res)?></span>
            <?php endif ?>
          ”</p>的搜索结果：
        </div>
      </div>
    <?php endif ?>
    

    <div class="weui_cells weui_cells_form  leimu">

      <div class="weui_cell">
        <div class="weui_cell_hd"><label for="firLeimu" class="weui_label">一级类目</label></div>
        <div class="weui_cell_bd weui_cell_primary">
          <input class="weui_input txtOverflow" id="firLeimu" type="text" value="" readonly="" placeholder="点击选择">
        </div>
      </div>

      <div class="weui_cell">
        <div class="weui_cell_hd"><label for="secLeimu" class="weui_label">二级类目</label></div>
        <div class="weui_cell_bd weui_cell_primary">
          <input class="weui_input txtOverflow" id="secLeimu" type="text" value="" readonly="" placeholder="点击选择">
        </div>
      </div>

    </div>

    <div class="weui_cells goodsList" id="goodsList">

    <?php if ($pro_list): ?>
    	<?php foreach ($pro_list as $key => $v): ?>
	    	<a class="weui_cell" href="/product/<?=Html::encode($v['id'])?>">
		        <div class="weui_cell_hd">
		        	<img src="<?=Html::encode($v['img_url'])?>" alt="" class="goodsImge">
		        </div>
		        <div class="weui_cell_bd weui_cell_primary">
		          <p class="goodsName"><?=Html::encode($v['name'])?></p>
		          <p class="infoTxt2">
		          <span class="area"><?=Html::encode($v['bname'])?></span>
		          <span class="right">已售<?=Html::encode($v['sale_sum']?$v['sale_sum']:'0')?><?=Html::encode($v['price_unit'])?></span>
		          </p>
		          <p class="infoTxt3">
			          <span class="price">￥<?=Html::encode($v['product_price'])?>/<?= Html::encode($v['price_unit'])?></span>
	                  <span class="right lowCount"></span>
		          </p>
		        </div>
		      </a>
	    <?php endforeach ?>
	<?php else: ?>
		<p style="text-align:center;padding-top:50px;">没有搜索到相关商品</p>
    <?php endif ?>
      

    </div>
    <!--滚动容器内的要加的加载提示-->
    <div class="weui-infinite-scroll" id="tips" style="display:none;">
      <div class="infinite-preloader"></div><!-- 菊花 -->
      正在加载... <!-- 文案，可以自行修改 -->
    </div>

  </div>

<script>
  $(function(){

    $('<div>',{
      'style': 'width: 40px;height: 40px;-webkit-border-radius: 50%;-moz-border-radius: 50%;border-radius: 50%;background: rgba(0,0,0,0.7);'+
      'position: fixed;bottom: 120px;right: 15px;text-align: center;z-index: 100',
      'id': 'fixPhone'
    }).html('<a href="tel:<?= $this->params['w_config']['contact_tel'] ?>"><img src="http://static.tianpinwang.com.cn/v1/mobile/images/fixedTel.png" style="margin-top: 6px;width: 68%;"/></a>').appendTo("body");

    $('<div>',{
      'style': 'width: 40px;height: 40px;-webkit-border-radius: 50%;-moz-border-radius: 50%;border-radius: 50%;background: rgba(0,0,0,0.7);'+
      'position: fixed;bottom: 60px;right: 15px;text-align: center;z-index: 100',
      'id': 'fixTotop'
    }).html('<img src="http://static.tianpinwang.com.cn/v1/mobile/images/fixedTotop.png" style="margin-top: 8px;width: 38%;"/>').appendTo("body");

    $('#fixTotop').click(function(){
      $('.goodsList').animate({scrollTop: 0},100);
    });

  	var list_1 = <?=$list_1?>;
    $("#firLeimu").picker({
		title: "请选择一级类目",
		cols: [{textAlign: 'center',values: list_1}],
		onClose:function(){
			$.post('',{'lv1name':$("#firLeimu").val()},function(data){
	    		$("#secLeimu").picker({
					title: "请选择二级类目",
					cols: [{textAlign: 'center',values: eval('('+data+')')}],
					onClose:function(){
						$.post('',{'lv2name':$("#secLeimu").val()},function(data){
				    		window.location.href = "/product?lv2="+data;
				    	})
					}
			    })
	    	})
		}
    });
  });
</script>

<script>
  $(function(){
    var loading = false;  //状态标记
    $('#ininint').infinite().on("infinite", function() {
      if(loading) return;
      $('#tips').attr('style','display:block');
      loading = true;
      var off = $('#goodsList').attr('value');
      if(!off){
        off = 1;
      }
      var $lv1 = <?php $lv1 = Yii::$app->request->get('lv1');echo $lv1?$lv1:'-1'; ?>;
      var $lv2 = <?php $lv2 = Yii::$app->request->get('lv2');echo $lv2?$lv2:'-2'; ?>;
      var $name = <?php $name = Yii::$app->request->get('name');echo $name?'"'.$name.'"':'-33'; ?>;

      var canshu = '';
      if($lv1 != '-1'){
        canshu += "lv1="+$lv1;
      }
      if($lv2 != '-2'){
        canshu += "&lv2="+$lv2;
      }
      if($name != '-33'){
        canshu += "&name="+$name;
      }

      $.get('/product/index?'+canshu,{'offset':off,},function(data){
        var data = eval('('+data+')');
        setTimeout(function() {
          var cont = '';
          if(data[0]){
            for (var i = 0; i < data.length; i++) {
              cont += '<a class="weui_cell" href="/product/'+data[i]["id"]+'"><div class="weui_cell_hd"><img src="'+data[i]["img_url"]+'" alt="" class="goodsImge"></div><div class="weui_cell_bd weui_cell_primary"><p class="goodsName">'+data[i]["name"]+'</p><p class="infoTxt2"><span class="area">'+data[i]['bname']+'</span><span class="right">已售'+data[i]["sale_sum"]+data[i]["price_unit"]+'</span></p><p class="infoTxt3"><span class="price">￥'+data[i]["product_price"]+'/'+data[i]["price_unit"]+'</span><span class="right lowCount"></span></p></div></a>';
            }
            $('#goodsList').attr('value',parseInt(off)+1);
            $("#goodsList").append(cont);
            loading = false;
            $('#tips').attr('style','display:none');
          }else{
            loading = false;
            $('#tips').text('没有更多了~');
          }
        }, 500);   //模拟延迟
      });
    });
  })
</script>